<template>
  <div
    class="layer-list-item lowcode-transition"
    :class="[layerMode === 'text' ? 'textMode' : '']"
  >
    <div class="item-content">
      <div class="image">
        <img :src="imageInfo" class="img" />
      </div>
      <div class="text">
        <div class="top">
          <el-tooltip
            effect="dark"
            :content="componentData.chartConfig.title"
            placement="top"
          >
            <div class="title">
              {{ componentData.chartConfig.title }}
            </div>
          </el-tooltip>
        </div>
        <div class="bottom">
          <div class="layer">第{{ componentData.attr.zIndex }}层</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, defineProps } from "vue";
import { useStore } from "vuex";
import { fetchImages } from "@/packages/index";
let store = useStore();

const layerMode = computed(() => store.getters["chartLayoutStore/layerType"]);

const props = defineProps({
  componentData: {
    type: Object,
    default: () => {},
  },
  layerMode: {
    type: String,
    default: "",
  },
});

const imageInfo = ref("");
// 获取图片
const fetchImageUrl = async () => {
  imageInfo.value = await fetchImages(props.componentData.chartConfig);
};
fetchImageUrl();
</script>

<style lang="scss" scoped>
.layer-list-item,
.textMode {
  width: 100%;
  height: 75px;
  padding: 10px 5px;
  .item-content {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    .image {
      flex: 1;
      height: 100%;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .text {
      height: 100%;
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      font-size: 12px;
      text-align: right;
      .top {
        .title {
          width: 100%;
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;
        }
      }
    }
  }
}
.textMode {
  height: 60px;
  .item-content {
    padding: 5px;
    .image {
      flex: 2;
      height: 100%;
      margin-right: 10px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .text {
      height: 100%;
      flex: 4;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      font-size: 12px;
    }
  }
}
</style>
